dojo.declare("MAccountPg", wm.Page, {

    start: function() {

    },
    "preferredDevice": "phone",

    accountSaveButtonClick1: function(inSender) {
        this.Add_Address.activate();
    },
    buttonRegistration1Click: function(inSender) {
      //  this.svRegister.update();
        
var isValid = true;
        var errorMsg = "Please enter valid data in required fields";

         if (!this.firstNameEditor1.getDataValue() || (this.firstNameEditor1 && this.firstNameEditor1.getDataValue() === "")) {
            isValid = false;
            errorMsg = "Please enter First Name";
        } else
         if (!this.lastNameEditor1.getDataValue() || (this.lastNameEditor1 && this.lastNameEditor1.getDataValue() === "")) {
            isValid = false;
            errorMsg = "Please enter Last Name";
        } else

        if (!this.cellPhoneEditor1.getDataValue() || (this.cellPhoneEditor1 && this.cellPhoneEditor1.getDataValue() === "") || this.cellPhoneEditor1.getInvalid()) {
            isValid = false;
            errorMsg = "Please enter valid Phone Number";
        }else
         if (!this.emailEditor2.getDataValue() || (this.emailEditor2 && this.emailEditor2.getDataValue() === "") || this.emailEditor2.getInvalid()) {
            isValid = false;
            errorMsg = "Please enter valid email Id";

        } else if (!this.passwordEditor2.getDataValue() || (this.passwordEditor2 && this.passwordEditor2.getDataValue() === "")) {
            isValid = false;
            errorMsg = "Please enter valid password";
        }else if (!this.largeTextArea2.getDataValue() || (this.largeTextArea2 && this.largeTextArea2.getDataValue() === "")) {
            isValid = false;
            errorMsg = "Please enter address";
        }
       
        if (isValid) {
            this.usernameInput.setDataValue(this.emailEditor2.getDataValue());
            this.passwordInput.setDataValue(this.passwordEditor2.getDataValue());
            console.log('calling service for registration');
            this.svRegister.update();
        } else {
            app.toastPosition = "center center";
            app.toastWarning(errorMsg, 2000);

            //this.ncRequiredFields.text=errorMsg;
            // this.ncRequiredFields.update();
        }
    },
    labelCoyRight9ReadOnlyNodeFormat: function(inSender, inValue) {

    },
    loginButtonClick: function(inSender) {
        this.svAuthenticateLogin.update();
    },
    svAuthenticateLoginSuccess: function(inSender, inDeprecated) {
     alert('succcess');
        try{
        var result = inSender.getItem(0);
        /* if (result) {
            app.vAccount=result; 
             this.ncLoginSuccsess.setShowing(true);
         } */
if (result.data.authenticated === true || result.data.authenticated === 'true') {
             
              app.vAccount.data.accountId = result.data.accountId;
                 app.vAccount.data.firstName = result.data.firstName;
              alert(app.vAccount.data.accountId);
                 app.vAccount.data.email = result.data.email;
                    app.vAccount.data.accountRole = result.data.accountRole;
                     app.vAccount.data.cellPhone = result.data.cellPhone;
                    app.vAccount.data.lastName = result.data.lastName;
                    app.vAccount.data.address = result.data.address;
                   
                    app.vAccount.data.password = result.data.password;
               this.ncLoginSuccsess.setShowing(true);
         }
        
         else {
                // this.notifyLoginError.update();
                this.ncLoginSuccsess.setShowing(true);
                //this.loginErrorMsg.setCaption("Invalid username or password.");
                this.passwordInput.clear();
                this.usernameInput.focus();

            }
        } catch (e) {

           // this.label1.caption = e;

        }
        //app.vAccount = result;
        
    },
    svRegisterSuccess: function(inSender, inDeprecated) {
        // alert('succcess');
        var result = inSender.getItem(0);
        console.log(result);
        console.log(result.data);
        app.vAccount = result;
        // alert(result.data.accountId);
        alert(app.vAccount.data.accountId);
    },

    buttonRegistration2Click: function(inSender) {
        //TBD validations
         alert(app.vAccount.data.accountId);
         this.svAccountUpdate.input.setValue("accountId",9);
         alert('get'+this.svAccountUpdate.input.getValue("accountId"));
        this.svAccountUpdate.update();
    },

    buttonRegistration3Click: function(inSender) {
        if (wm.Page.getPage("MHomePg")) {
            wm.Page.getPage("MHomePg").navButton1.click();
        }
    },
    layer3Show: function(inSender) {

        this.firstNameEditor2.setDisplayValue(app.vAccount.data.firstName);
        this.lastNameEditor2.setDisplayValue(app.vAccount.data.lastName);
        this.cellPhoneEditor2.setDisplayValue(app.vAccount.data.cellPhone);
        this.emailEditor3.setDisplayValue(app.vAccount.data.email);
        this.passwordEditor3.setDisplayValue(app.vAccount.data.password);
        this.largeTextArea1.setDisplayValue(app.vAccount.data.address);
    },
    svAccountUpdateSuccess: function(inSender, inDeprecated) {
	 var result = inSender.getItem(0);
        console.log(result);
        console.log(result.data);
        app.vAccount = result;
        // alert(result.data.accountId);
        alert(app.vAccount.data.accountId);	
	},
	buttonRegistration4Click: function(inSender) {
       
		  
           this.owner.setPageName("MCustomerOrderHistoryPg");


	},
	_end: 0
});